package com.example.stock;

import android.app.AlertDialog;
import android.content.Context;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;


public class SellDialog extends AlertDialog implements OnClickListener {
    private EditText etname,etprice;  //编辑框
    private Button btnConfrim, btnCancel;  //确定取消按钮
    private TextView vtitle;
    private String tscost;
    private int id,num;
    private float buyp,buyf;
    private OnEditInputFinishedListener mListener; //接口

    public interface OnEditInputFinishedListener{
        void editInputFinished(float price,float buyp,float buyf,int num,int id);
    }

    protected SellDialog(Context context, OnEditInputFinishedListener mListener, String cost,int inid,String strnum,float buyprice,float buyfee) {
        super(context);
        this.mListener = mListener;
        tscost=cost;
        id=inid;
        num=Integer.parseInt(strnum);
        buyp=buyprice;
        buyf=buyfee;
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_addorless);

        //控件
        ((TextView)findViewById(R.id.textView4)).setVisibility(View.GONE);
        ((TextView)findViewById(R.id.num)).setVisibility(View.GONE);
        vtitle = (TextView)findViewById(R.id.textView);
        vtitle.setText("成本价");
        etname = (EditText)findViewById(R.id.name);
        etname.setText(tscost);
        vtitle = (TextView)findViewById(R.id.textView3);
        vtitle.setText("卖出价");
        etprice = (EditText)findViewById(R.id.price);
        etprice.requestFocus();

        btnConfrim = (Button)findViewById(R.id.btn_confirm);
        btnCancel = (Button)findViewById(R.id.btn_cancel);


        btnConfrim.setOnClickListener(this);
        btnCancel.setOnClickListener(this);
    }

    @Override
    public void onClick(View v) {
        if (v.getId() == R.id.btn_confirm) {
            //确定
            if (mListener != null) {
                float price=Float.parseFloat(etprice.getText().toString());
                if(price>0.0f)mListener.editInputFinished(price,buyp,buyf,num,id);
            }
            dismiss();
        }else {
            //取消
            dismiss();
        }
    }

}
